package cn.dengta.webapp.trade.form;

import cn.dengta.common.context.I18N;
import cn.dengta.common.validator.Check;
import cn.dengta.common.validator.NotEmpty;
import cn.dengta.common.validator.Phone;
import cn.dengta.common.validator.Trim;
import cn.dengta.context.model.TradeFormI18nKey;
import cn.dengta.webapp.base.form.BaseForm;
import cn.dengta.webapp.trade.entity.CashAccount;
import cn.dengta.webapp.trade.model.Currency;
import cn.dengta.webapp.trade.model.PayPlatform;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Assert;

import static cn.dengta.context.model.TradeFormI18nKey.*;

/**
 * 提现账号
 *
 * @author yuqidi
 * @since 2022-03-24
 */
@Setter
@Getter
@Accessors(chain = true)
public class CashAccountForm extends BaseForm<CashAccount> {

	public Long id;
	/** 支付平台 */
	@Check(CASH_ACCOUNT_FORM_PLATFORM)
	public Integer platform;
	/** 手机号 */
	@Check(value = CASH_ACCOUNT_FORM_PHONE, required = false)
	@Trim
	@Phone
	public String phone;
	/** 真实姓名 */
	@Check(CASH_ACCOUNT_FORM_REAL_NAME)
	@Trim
	@NotEmpty
	public String realName;
	/** 提现账号 */
	@Check(CASH_ACCOUNT_FORM_ACCOUNT)
	@Trim
	@NotEmpty
	public String account;
	/** 提现币种 */
	@Check(CASH_ACCOUNT_FORM_CURRENCY)
	@Trim
	@NotEmpty
	public String currency;

	/**
	 * YooPay提现银行Code
	 */
	private String bankCode;

	@Override
	public void validate() {
		super.validate();
		Assert.notNull(PayPlatform.of(platform));
		Assert.notNull(Currency.of(currency), () -> I18N.msg(TradeFormI18nKey.CASH_ACCOUNT_FORM_CURRENCY_NEED));
		//todo yooPay提现时银行code不能为空
		//Assert.notNull(PayPlatform.YooPay.value.equals(PayPlatform.of(platform).value) ? bankCode : PayPlatform.of(platform), () -> I18N.msg());
	}

}
